Manipulating the Colors in a Color Set Object
If you are using indexed color space, you can gain access to the array of colors in the space's color set or to any contiguous subset of the colors in the array. You can then inspect, rearrange, modify, or add or delete colors from the array.For example, suppose you want to sort the colors in a color set so that they will
display in a visually useful manner in a palette for the user. You could first call theGXGetColorSet
function to get the array of colors. You could then sort the colors (say, by hue (H
) ingxHSVSpace
), and then return the array to the color set by calling theGXSetColorSet
function.Alternatively, suppose you already have a luminance-sorted array of colors in a color set, and you want to convert the first (darkest) color in the array to pure black. Instead of accessing the entire array, you can call
GXGetColorSetParts
to get only the first color in the array. You can then change that color to black, and reinsert it in the color set by callingGXSetColorSetParts
.To add colors to or delete colors from a color set, call
GXGetColorSet
, modify the color-value array as needed, and then callGXSetColorSet
to place the new array in
the color set.To change the color space of a color set, follow this sequence of calls:
Remember that simply changing the color space of a color set does not convert the individual color values from one space to the other.
- Call
GXGetColorSet
to obtain the color-value array.- Call
GXConvertColor
on each color value in the array to convert the individual color values from one space to the other.- Call
GXSetColorSet
to place the same array in the color set, but with a different value specified for the color space.
As an example of color-set manipulation, the following code fragment from a drawing routine matches each of the colors of a color set used by the shape matchShape to a specific color profile (
qmsProfile
). The code uses the GXGetColorSet function to fill out a temporary array of color values (mycolors) from the color set, converts each color (from RGB space with anil
profile to RGB space withqmsProfile
, in this case) with the GXConvertColor function, and then reassigns the color values to the color set
with the GXSetColorSet function.
gxSetColor mycolors[256]; oldColorCount = GXGetColorSet(GXGetShapeColorSet(matchShape), nil, mycolors); for (i = 0; i < oldColorCount; i++) { gxColor tmpColor; tmpColor.space = gxRGBSpace; tmpColor.profile = nil; tmpColor.element.rgb = mycolors[i].rgb; GXConvertColor(&tmpColor,gxRGBSpace, nil, qmsProfile); mycolors[i].rgb = tmpColor.element.rgb; } GXSetColorSet(GXGetShapeColorSet(matchShape), gxRGBSpace, oldColorCount, mycolors);TheGXGetColorSet
function is described on page 4-73. TheGXSetColorSet
function is described on page 4-74. TheGXGetColorSetParts
function is described on page 4-75. TheGXSetColorSetParts
function is described on page 4-76.